package newsLike

import (
	"gin/common/lib/gorm"
	"gin/dao/entity"
)

// Add 点赞动态
func Add(p entity.NewsLike) {
	gorm.GinDb.SubTable("cmf_users_news_like", p.NewsId).Create(&p)
}

// GetById 根据id获取点赞动态
func GetById(id int64, uid int64) entity.NewsLike {
	info := entity.NewsLike{}
	gorm.GinDb.SubTable("cmf_users_news_like", id).
		Where("news_id = ? and uid = ?", id, uid).Limit(1).Find(&info)
	return info
}

// Del 删除点赞
func Del(id, uid int64) {
	gorm.GinDb.SubTable("cmf_users_news_like", id).
		Where("news_id = ? and uid = ?", id, uid).Delete(&entity.NewsLike{})
}

// IsExist 是否点赞
func IsExist(uid, newsId int64) bool {
	var id int64
	gorm.GinDb.SubTable("cmf_users_news_like", id).
		Where("news_id = ? and uid = ?", newsId, uid).Limit(1).Pluck("id", &id)
	return id > 0
}
